Purpose
Similar to the substring task, the string slice task extracts part of a provided string and returns the extracted part in a new string. The part of the string you want to extract is specified between the start and end indexes, or to the end of the string.
Potential Use Case
If you need to extract only the telephone area code from an incoming string, using slice would provide the means by which to accomplish this.
Properties
Input and output properties are shown below.
| Incoming | Type | Description |
|---|---|---|
str |
String | Required. The string that contains the value to be extracted. |
beginIndex |
Number | Required. The position in the string to begin the extraction. The first character in the string has position 0, the second has position 1, and so on. Numbering starts (and defaults) at position '0' (the beginning of the str value). |
endIndex |
Number | Optional. The position in the string to stop the extraction. Numbering also begins from the start of the string and represents the point up to, but not including, where slicedString should end the extraction. |
Note: If the value of
endIndexis less than the value ofbeginIndex, the output value ofslicedStringwill return an empty string (""). If this is not the behavior that is desired, then consider using thesubstringTask Reference.
| Outgoing | Type | Description |
|---|---|---|
slicedString |
String | The extracted value in str that is specified by the beginIndex and endIndex parameters. |
Examples
Example 1
In the IAP example shown below:
The
strvariable has been statically set as800-555-1212.The
beginIndexvariable has been set to7, indicating the extraction should begin at the second dash in thestrvalue.The
endIndexvariable has been set to4, indicating the extraction should only proceed up until (but not including) character 4. Remember, character numbering starts at '0', so character 4 in this case is the first number "5" character.Because the
beginIndexvalue is greater than theendIndexvalue, theslicedStringoutput variable will have the value of""(an empty string).
Example 2
In the IAP example shown below:
The
strvariable has been statically set as800-555-1212.The
beginIndexvariable has been set to4, indicating the extraction should begin at position number 4 of thestrvalue.The
endIndexvariable has been set to7, indicating the extraction should only proceed up until (but not including) character 7. Remember, numbering starts at '0', so character 7 in this case is the second "-" character.The
slicedStringoutput variable will have the value of555.